using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using MEA.AE_Data;
using MEA.Chart;

namespace MEA.AE_BusinessLogic
{
	public class UIGraphDatLog : UIGraphBase
	{
		private IContainer components;

		public UIGraphDatLog()
			: base(ConfigBase.EGraphicAspect.eShowGraphDataLog)
		{
			initCheckedDataGridViewGraphSignals();
			AddLeadInOutToToolstrip();
			toolStripButtonRecord.Visible = false;
			toolStripLabelLiveView.Visible = false;
			toolStripButtonStop.Visible = false;
			toolStripButtonExport.Visible = false;
			tend = 600f;
			toolStripButtonExport.Click += base.toolDataLogStripButtonExport_Click;
		}

		private void AddLeadInOutToToolstrip()
		{
			toolStripSeparator7.Visible = true;
			toolStripComboBoxLeadinOut.Enabled = true;
			toolStripComboBoxLeadinOut.Visible = true;
			toolStripComboBoxLeadinOut.Text = "LeadIn-Out Times";
			toolStripComboBoxLeadinOut.Items.AddRange(new string[1] { " " });
			toolStripComboBoxLeadinOut.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
			toolStripComboBoxLeadinOut.AutoCompleteSource = AutoCompleteSource.CustomSource;
			toolStripButtonShowLInOut.Enabled = true;
			toolStripButtonShowLInOut.Visible = true;
		}

		public void showLeadInOutEV(object sender, EventArgs e)
		{
			if (e is ServiceLayerLeadINOutEventArg)
			{
				ServiceLayerLeadINOutEventArg serviceLayerLeadINOutEventArg = (ServiceLayerLeadINOutEventArg)e;
				activeECU = serviceLayerLeadINOutEventArg.SelectedECU;
				showLeadInOut();
				if (fileInfo == null)
				{
					fileInfo = new FileInfoHnd();
					fileInfo.SetFileInfoStrm(ref serviceLayer.dataLogInfo, base.Location);
				}
			}
		}

		protected override void setScrollbarRange()
		{
			if (hScrollBar1.InvokeRequired)
			{
				dbg_setscroll method = setScrollbarRange;
				Invoke(method, new object[0]);
				return;
			}
			lock (functs.SyncRoot)
			{
				Function function = (Function)functs[functs.Count - 1];
				xmin = 0;
				xmax = 10;
				if (function.points.Count > 1)
				{
					PointF pointF = function.points[0];
					xmin = (int)function.points[function.points.Count - 1].X;
					xmax = (int)pointF.X;
				}
				lock (hScrollBar1)
				{
					if (xmin < hScrollBar1.Minimum)
					{
						hScrollBar1.Minimum = xmin;
					}
					if (xmax > hScrollBar1.Maximum)
					{
						hScrollBar1.Maximum = xmax + 10;
					}
				}
			}
		}

		public override void UpdateData(object sender, EventArgs e)
		{
			for (int i = 0; i < functs.Count; i++)
			{
				Var var = (Var)base.GraphVars[i];
				lock (var)
				{
					lock (functs.SyncRoot)
					{
						Function function = (Function)functs[i];
						lock (function)
						{
							function.points.Clear();
							function.AddPoints(ref var.data);
							function.timestamps = var.timestamps;
							function.sessionMarkers = var.SessionMarker;
							function.SessionMarkerComment = var.SessionMarkerComment;
							function.Visible = false;
						}
					}
				}
				if (i == functs.Count - 1)
				{
					setScrollbarRange();
				}
			}
			checkedDataGridViewGraphSignals.Invoke((MethodInvoker)delegate
			{
				CheckedListBoxSignalsItemCheck(0);
			});
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private new void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Text = "UIGraphDatLog";
		}
	}
}
